package cn.iocoder.yudao.module.wrdk.controller.admin.licencefile;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wrdk.controller.admin.licencefile.vo.*;
import cn.iocoder.yudao.module.wrdk.dal.dataobject.licencefile.wrdklicencefileDO;
import cn.iocoder.yudao.module.wrdk.convert.licencefile.wrdklicencefileConvert;
import cn.iocoder.yudao.module.wrdk.service.licencefile.wrdklicencefileService;

@Api(tags = "Crazy!!!!!管理后台 - 地块许可证文件")
@RestController
@RequestMapping("/wrdk/wrdklicencefile")
@Validated
public class wrdklicencefileController {

    @Resource
    private wrdklicencefileService wrdklicencefileService;

    @PostMapping("/create")
    @ApiOperation("创建地块许可证文件")
    @PreAuthorize("@ss.hasPermission('wrdk:wrdklicencefile:create')")
    public CommonResult<Long> createwrdklicencefile(@Valid @RequestBody wrdklicencefileCreateReqVO createReqVO) {
        return success(wrdklicencefileService.createwrdklicencefile(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新地块许可证文件")
    @PreAuthorize("@ss.hasPermission('wrdk:wrdklicencefile:update')")
    public CommonResult<Boolean> updatewrdklicencefile(@Valid @RequestBody wrdklicencefileUpdateReqVO updateReqVO) {
        wrdklicencefileService.updatewrdklicencefile(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除地块许可证文件")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('wrdk:wrdklicencefile:delete')")
    public CommonResult<Boolean> deletewrdklicencefile(@RequestParam("id") Long id) {
        wrdklicencefileService.deletewrdklicencefile(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得地块许可证文件")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('wrdk:wrdklicencefile:query')")
    public CommonResult<wrdklicencefileRespVO> getwrdklicencefile(@RequestParam("id") Long id) {
        wrdklicencefileDO wrdklicencefile = wrdklicencefileService.getwrdklicencefile(id);
        return success(wrdklicencefileConvert.INSTANCE.convert(wrdklicencefile));
    }

    @GetMapping("/list")
    @ApiOperation("获得地块许可证文件列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('wrdk:wrdklicencefile:query')")
    public CommonResult<List<wrdklicencefileRespVO>> getwrdklicencefileList(@RequestParam("ids") Collection<Long> ids) {
        List<wrdklicencefileDO> list = wrdklicencefileService.getwrdklicencefileList(ids);
        return success(wrdklicencefileConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得地块许可证文件分页")
    @PreAuthorize("@ss.hasPermission('wrdk:wrdklicencefile:query')")
    public CommonResult<PageResult<wrdklicencefileRespVO>> getwrdklicencefilePage(@Valid wrdklicencefilePageReqVO pageVO) {
        PageResult<wrdklicencefileDO> pageResult = wrdklicencefileService.getwrdklicencefilePage(pageVO);
        return success(wrdklicencefileConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出地块许可证文件 Excel")
    @PreAuthorize("@ss.hasPermission('wrdk:wrdklicencefile:export')")
    @OperateLog(type = EXPORT)
    public void exportwrdklicencefileExcel(@Valid wrdklicencefileExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<wrdklicencefileDO> list = wrdklicencefileService.getwrdklicencefileList(exportReqVO);
        // 导出 Excel
        List<wrdklicencefileExcelVO> datas = wrdklicencefileConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "地块许可证文件.xls", "数据", wrdklicencefileExcelVO.class, datas);
    }

}
